package edu.washington.ling.syntric.struct.projection;

import java.util.List;
import java.util.LinkedList;

import edu.stanford.nlp.util.StringUtils;

public class BiProjectionRule {
	private List<String> rootLabels;
	private String headChildLabel;
	private List<ProjectionNode> leftDependentForest;
	private List<ProjectionNode> rightDependentForest;
	
	public BiProjectionRule(List<String> rootLbls, String headChildLbl) {
		rootLabels = rootLbls;
		headChildLabel = headChildLbl;
		leftDependentForest = new LinkedList<ProjectionNode>();
		rightDependentForest = new LinkedList<ProjectionNode>();
	}
	
	public String getRootLabel() {
		return rootLabels.get(0);
	}
	public List<String> getRootLabels() {
		return rootLabels;
	}
	public String getHeadChildLabel() {
		return headChildLabel;
	}
	
	public String getSpine() {
		List<String> spineStrs = new LinkedList<String>();
		for (String rootLabel: rootLabels) {
			spineStrs.add(rootLabel);
		}
		spineStrs.add(headChildLabel);
		return StringUtils.join(spineStrs, " ");
	}
	
	public void addToLeftDependentForest(List<ProjectionNode> depForest) {
		leftDependentForest.addAll(depForest);
	}
	public void addToRightDependentForest(List<ProjectionNode> depForest) {
		rightDependentForest.addAll(depForest);
	}
	public boolean hasLeftDependentForest() {
		return (leftDependentForest.size() != 0);
	}
	public boolean hasRightDependentForest() {
		return (rightDependentForest.size() != 0);
	}
	public List<ProjectionNode> getLeftDependentForest() {
		return leftDependentForest;
	}
	public List<ProjectionNode> getRightDependentForest() {
		return rightDependentForest;
	}
	public BiProjectionNode toNode() {
		BiProjectionNode projNode = new BiProjectionNode(rootLabels, headChildLabel);
		if (this.hasLeftDependentForest()) {
			projNode.insertLeftDependentForest(this.getLeftDependentForest());
		}
		if (this.hasRightDependentForest()) {
			projNode.insertRightDependentForest(this.getRightDependentForest());
		}
		return projNode;
	}
}
